<!-- SELECT2 EXAMPLE -->
<div class="box box-default">
	<div class="box-header with-border">
		<h3 class="box-title">添加产品</h3>
	</div>
	<!-- /.box-header -->
	<div class="box-body">
		<div class="row">
			<div class="col-md-11">
				<form class="form-horizontal" action="/manage/product/pro_save" method="post" name="myform" id="myform">
					<div class="form-group">
						<label class="col-md-2 non-rpad control-label" for="title">产品名称：</label>
						<div class="col-md-6 non-lrpad" style="line-height: 24px">
							<input type="text" required name="title" id="title" class="form-control" value="<!--{$data['title']}-->" />
						</div>
						<div class="col-md-3 text-center">
							<label class="checkbox-inline"> <input id="is_recommand" type='checkbox' name="is_recommand" value="1"
							<!--{if($data['is_recommand']==1){echo "checked";}}--> />首页推荐
							</label> 
							<a class="btn btn-warning" href="javascript:;" onclick="add_attr()">添加属性</a>
						</div>
					</div>
					<div class="form-group" id="attr">
						<input id="has_attr" type="hidden" name="has_attr" value=
						<!--{echo empty($data)?0:$data['has_attr']}-->
						/>
						<!--{if($attr)}-->
						<!--{foreach($attr as $k=>$v)}-->
						<div class='col-md-8 col-md-offset-2' id='attr_<!--{$k}-->' style='margin-top: 5px;'>
							属性名称：<input name='pro_attr[<!--{$k}-->][attr]' type='text' value='<!--{$v['attr_attr']}-->' />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;属性值：<input name='pro_attr_value[<!--{$k}-->][attr_value]' type='text' value='<!--{$v['attr_name']}-->' />&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-danger" href='javascript:;' onclick='$("#attr_<!--{$k}-->").remove();return false;'>删除属性</a>
						</div>
						;
						<!--{/foreach}-->
						<!--{/if}-->
					</div>
					<div class="form-group">
						<label class="col-md-2 non-rpad control-label" for="pid">所属分类：</label>
						<div class="col-md-3 non-lrpad" style="line-height: 24px">
							<select name="pid" class="form-control" id='pid'>
								<!--{foreach($cat as $k=>$v)}-->
								<option value="<!--{$k}-->"<!--{ if($data['pid']==$k){echo "selected";}}-->>
									<!--{$v}--></option>
								<!--{/foreach}-->
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-2 non-rpad control-label" for="model">产品型号：</label>
						<div class="col-md-6 non-lrpad" style="line-height: 24px">
							<input type="text" name="model" id="model" class="form-control" value="<!--{$data['model']}-->" />
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-2 non-rpad control-label" for="price">价格：</label>
						<div class="col-md-6 non-lrpad" style="line-height: 24px">
							<input type="text" name="price" id="price" class="form-control" value="<!--{$data['price']}-->" />
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-2 non-rpad control-label" for="seo_title">SEO标题：</label>
						<div class="col-md-6 non-lrpad" style="line-height: 24px">
							<input type="text" required name="seo_title" id="seo_title" class="form-control" value="<!--{$data['seo_title']}-->" />
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-2 non-rpad control-label" for="desc">描述：</label>
						<div class="col-md-6 non-lrpad" style="line-height: 24px">
							<input type="text" required name="desc" id="desc" class="form-control" value="<!--{$data['desc']}-->" />
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-2 non-rpad control-label">产品图：</label>
						<div class="col-xs-6 non-lrpad" style="line-height: 35px">
							<div class="col-xs-6">
								<button type="button" class="btn btn-success col-xs-10">+上传图片</button>
								<input type="file" name="upload" id="thumb" class="col-xs-10 btn-translatefile" onchange="ajaxFileUpload('thumb');"> <input type="hidden" name="thumb" id="field_thumb" autocomplete="off" value="<!--{$data['thumb']}-->"> <img id="file_thumb" src="<!--{$data['thumb']}-->" class="uplaod">
							</div>
						</div>
					</div>	
					<div class="form-group">
						<label class="col-md-2 non-rpad control-label" for="content">产品说明：</label>
						<div class="col-md-10 non-lrpad" style="line-height: 24px">
							<script id="container" name="content"><!--{$data['content']}--></script>
						</div>
					</div>
					<div class="form-group">
						<label class="col-md-2 non-rpad control-label" for="add_time"> 更新时间 ：</label>
						<div class="col-md-3 non-lrpad">
							<input class="setdate form-control" type="text" name="add_time" id="add_time" value="<!--{echo $data['add_time']?date('Y-m-d H:i:s',$data['add_time']):date('Y-m-d H:i:s')}-->" />
						</div>
					</div>
					<div class="form-group">
						<!--{if($id)}-->
						<input type="hidden" name="id" value="<!--{$id}-->">
						<!--{/if}-->
						<input class="col-md-2 col-md-offset-5 btn btn-success" type="submit" value="提交" />
					</div>
				</form>
			</div>

		</div>
		<!-- /.row -->
	</div>
	<!-- /.box-body -->
</div>
	<style>
.btn-translatefile {
	position: absolute;
	height: 34px;
	opacity: 0;
	cursor: pointer;
}

img[src=''] {
	display: none;
}

img.uplaod {
	height: 120px;
	margin-left: 10px;
}

.version-list {
	display: none;
}
</style>
<!-- /.box -->
<script src="/static/js/WdatePicker.js"></script>
<script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="/static/js/ajaxfileupload.js"></script>
<script type="text/javascript">
		var attr_key=<!--{echo $attr?count($attr):0;}-->;
		var ue = UE.getEditor('container', {
			initialFrameHeight : 500,
		});
		$(document).ready(function() {
			$(".setdate").click(function() {
				var old_val=$(this).val();
				WdatePicker({
					dateFmt : 'yyyy-MM-dd HH:mm:ss',
				});
			});
			
		});
		function add_attr(){
			$('#has_attr').val("1");
			var $html="<div class='col-md-8 col-md-offset-2' id='attr_"+attr_key+"' style='margin-top:5px;'>属性名称：<input name='pro_attr["+attr_key+"][attr]' type='text' value='' />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;属性值：<input name='pro_attr_value["+attr_key+"][attr_value]' type='text' value='' />&nbsp;&nbsp;&nbsp;&nbsp;<a class=\"btn btn-danger\" href='javascript:;' onclick='$(\"#attr_"+attr_key+"\").remove();return false;'>删除属性</a></div>";
			 $("#attr").append($html);
			 attr_key++;
		}
		function ajaxFileUpload(id) {
			var url = '/manage/product/uploadimg';
			$.ajaxFileUpload({
				url : url, //需要链接到服务器地址
				secureuri : false,
				fileElementId : id, //文件选择框的id属性
				dataType : 'json', //服务器返回的格式，可以是json
				success : function(data, status) {
					//alert(this.fileElementId);
					var that = this;
					if (data.status == '1') {
						$('#file_' + that.fileElementId).attr('src',data.data);
						$('#field_' + that.fileElementId).val(data.data);
					} else {
						alert(data.info);
					}
				},
				error : function(data, status, e) {
					alert(e);
				}
			});
		}
		</script>